<?php
// +----------------------------------------------------------------------
// | PHP [ JUST YOU ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2017 http://www.jyphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: FlyingPig <flyingpigfp@163.com>
// +----------------------------------------------------------------------

namespace App\Http\Controllers;


use App\Exceptions\ApiException;
use Illuminate\Support\Facades\DB;

class UserBingDing extends Base
{

    public function handle()
    {
        if ($this->uid == $this->param['bingding_uid']) {
            throw new ApiException('不能绑定自己');
        }
        $nick_name = DB::table('t_player_info')->where('id',$this->param['bingding_uid'])->where('status',1)->value('nick_name');
        if (empty($nick_name)) {
            throw new ApiException('要绑定的UID不存在');
        }
        $bingding_uid = $this->param['bingding_uid'];
        DB::select("INSERT INTO `t_users_binding`(`uid`,`bindding_uid`) VALUES ($this->uid,$bingding_uid) ON  DUPLICATE KEY UPDATE `uid` = $this->uid");
        return $this->returnData(['nick_name' => $nick_name,'uid' => $this->param['bingding_uid']]);
    }

}